import { literatureList } from "../../../api/index";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        activeKey: 0,
        literatureData: [],
        dictData: [
            {
                id: ""
            }
        ],
        id: "",
    },
    getData(id: string) {
        literatureList(id).then((r: any) => {
            this.setData({
                literatureData: r
            })
        })
    },
    onLoad() {
        const app = getApp();
        // 获取实例上存储的数据
        this.setData({
            dictData: app.globalData.literatureDict,
            id: app.globalData.literatureDict[this.data.activeKey].id
        });
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        // 获取文献数据
        this.getData(this.data.id)
    },

    // tab切换
    tabChange(e: { detail: number; }) {
        const i = e.detail;
        this.setData({
            activeKey: i
        });
        this.getData(this.data.dictData[i].id);
    },
})